#!/bin/bash

usage(){
    echo ""
    echo "Usage: $0 build_method test_to_run [options]"
    echo ""
    echo "build_method: -p|-c|-b build.xml"
    echo "    -p                      : use $LEOHOME/test.xml"
    echo "    -c                      : use ./build.xml"
    echo "    -b build.xml            : specify the build.xml file to use"
    echo ""
    echo "test_to_run -t -Dtests.to.run= | -m -Dmodules.to.test="
    echo "    -t -Dtests.to.run=      : specify <class_name>:<method_name> to run the test"
    echo "    -m -Dmodules.to.test=   : specify <module_name>.<sub-module_name> to run the test"
    echo ""
    echo "options:"
    echo "    -f                      : -Dno.full.build=false"
    echo ""
}

if [ $# -lt 2 ]; then
    usage;
    exit 1;
fi

fullbuild="-Dno.full.build=true"

while getopts "pcfb:t:m:nh" option
do 
    case "${option}"
    in
        p) buildxml="-f ${LEOHOME}/test.xml";;
        c) buildxml="";;
        b) buildxml="-f ${OPTARG}";;
        f) fullbuild="-Dno.full.build=false";;
        t) testmtd="-Dtests.to.run=${OPTARG}";;
        m) testmtd="-Dmodules.to.test=${OPTARG}";;
        h) usage; exit 1;;
    esac
done

ant ${buildxml} ${fullbuild} ${testmtd}

